/**
 * @file user_led.c
 *
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "user_include.h"


#define GPIO_OUTPUT_IO_0    1
#define GPIO_OUTPUT_PIN_SEL  ((1ULL<<GPIO_OUTPUT_IO_0) )

void led_init(void)
{
    //zero-initialize the config structure.
    gpio_config_t io_conf = {};
    //disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);
}

void user_led_task(void *args)
{
    static int led_status = 0;

    led_init();

    while(1) {
        vTaskDelay(500 / portTICK_PERIOD_MS);
        if (ip_info_flag.valid == 0)
        {
            led_status = !led_status;
        	gpio_set_level(GPIO_OUTPUT_IO_0, led_status);
        }
        else
        {
            led_status = 0;
        	gpio_set_level(GPIO_OUTPUT_IO_0, led_status);
        }
    }
}
